package com.family.gmall.product.api;

import com.alibaba.fastjson.JSONObject;
import com.family.gmall.common.result.Result;
import com.family.gmall.model.product.entity.*;
import com.family.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Auther: family
 * @Date: 2023/7/14 08:59
 * @Description:
 */
@Api(tags = "微服务接口")
@RestController
@RequestMapping("/api/product/inner")
public class ProductApiController {
    @Resource
    private ManageService manageService;

    @ApiOperation("根据skuId获取sku信息")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return manageService.getSkuInfo(skuId);
    }

    @ApiOperation("通过三级分类id查询分类信息")
    @ApiImplicitParam(name = "category3Id", value = "category3Id", required = true)
    @GetMapping("/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id) {
        return manageService.getCategoryViewByCategory3Id(category3Id);
    }

    @ApiOperation("获取sku价格")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId) {
        return manageService.getSkuPrice(skuId);
    }

    @ApiOperation("获取销售信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuId", value = "skuId", required = true),
            @ApiImplicitParam(name = "spuId", value = "spuId", required = true)
    })
    @GetMapping("/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable Long skuId, @PathVariable Long spuId) {
        return manageService.getSpuSaleAttrListCheckBySku(skuId, spuId);
    }

    @ApiOperation("实现商品切换")
    @ApiImplicitParam(name = "spuId", value = "spuId", required = true)
    @GetMapping("/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId) {
        return manageService.getSkuValueIdsMap(spuId);
    }

    @ApiOperation("获取分类树")
    @GetMapping("/category/tree")
    public Result getCategoryTree() {
        List<JSONObject> list = manageService.getBaseCategoryList();
        return Result.ok(list);
    }

    @ApiOperation("通过品牌Id 集合来查询数据")
    @ApiImplicitParam(name = "tmId", value = "tmId", required = true)
    @GetMapping("/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable("tmId") Long tmId) {
        return manageService.getTrademarkByTmId(tmId);
    }

    @ApiOperation("通过skuId 集合来查询数据")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId) {
        return manageService.getAttrList(skuId);
    }
}
